package com.mz.mattress.admin.api.merchant;

import com.mz.mattress.admin.api.resp.CashOutResp;
import com.mz.mattress.admin.common.Holder;
import com.mz.mattress.admin.service.HongBaoService;
import com.mz.mattress.api.common.Constants;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.jwt.MerchantJwt;
import com.mz.mattress.api.util.IpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping(Constants.MERCHANT_PATH + "/hongBao")
public class HongBaoController {

    @Autowired
    private HongBaoService hongBaoService;

    /**
     * 用户 提现到微信
     * @param money
     * @return
     */
    @GetMapping("/cashOut")
    public Result<CashOutResp> cashOut(@RequestParam Integer money, HttpServletRequest request) {
        MerchantJwt userJwt = Holder.MERCHANT_JWT_THREAD_LOCAL.get();
        log.info("memberMerId={}", userJwt.getMemberMerId());
        String ip = IpUtil.client(request);
        return hongBaoService.cashOut(userJwt.getMemberMerId(), money, ip);
    }

    @GetMapping("/queryIsPaid")
    public Result<String> queryIsPaid(@RequestParam String cashId) {
        return hongBaoService.queryIsPaid(cashId);
    }

}
